import component from "element-plus/es/components/tree-select/src/tree-select-option.mjs";
import path from "path-browserify";
import { createRouter, createWebHashHistory } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Dashboard",
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error/404.vue"),
        meta: { hidden: true },
      },
      {
        path: "profile",
        name: "Profile",
        component: () => import("@/views/profile/index.vue"),
        meta: { title: "个人中心", icon: "user", hidden: true },
      }
      // {
      //   path: "my-notice",
      //   name: "MyNotice",
      //   component: () => import("@/views/system/notice/components/MyNotice.vue"),
      //   meta: { title: "我的通知", icon: "user" },
      // },
    ],
  },
  {
    path: '/teacher',
    component: Layout,
    name: 'Teacher', // 路由名称首字母大写，遵循命名规范
    meta: { title: '教师管理', icon: 'role' }, // 一级路由直接显示在菜单中
    children: [
      {
        path: '', // 空路径表示默认子路由
        name: 'TeacherList',
        component: () => import('@/views/teacher/index'),
        meta: { title: '教师管理', icon: 'role' }
      }
    ]
  },
  {
    path: '/subject',
    component: Layout,
    redirect: '/subject/list',
    name: 'subject',
    meta: { title: '课程分类', icon: 'tree' },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/teacher/index'),
        meta: { title: '课程分类列表', icon: 'table' }
      },
      {
        path: 'save',
        name: 'save',
        component: () => import('@/views/teacher/index'),
        meta: { title: '导入课程分类', icon: 'tree' }
      }
    ]
  }
];


/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app) {
  app.use(router);
}

export default router; 